import { defineStore } from "pinia";
import { getLocal, setLocal } from "@/utils/localUtil";

interface SearchState {
  searchHistory: any[];
}

export const useSearchStore = defineStore({
  id: "search",
  state: (): SearchState => ({
    searchHistory: getLocal("search-history") || [],
  }),
  getters: {
    getSearchHistory(): any[] {
      return this.searchHistory;
    },
  },
  actions: {
    setSearchHistory(data: any[]) {
      this.searchHistory = data;
      setLocal("search-history", data);
    },
  },
});
